<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<style>
    body {
        height: 2000px;
    }
    
    .modal {
        position: fixed;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0.5);
        opacity: 0;
        visibility: hidden;
        transform: scale(1.1);
        transition: visibility 0s linear 0.25s, opacity 0.25s 0s, transform 0.25s;
    }
    
    .modal-content {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        background-color: white;
        padding: 1rem 1.5rem;
        width: 24rem;
        border-radius: 0.5rem;
    }
    
    .close-button {
        float: right;
        width: 1.5rem;
        line-height: 1.5rem;
        text-align: center;
        cursor: pointer;
        border-radius: 0.25rem;
        background-color: lightgray;
    }
    
    .close-button:hover {
        background-color: darkgray;
    }
    
    .show-modal {
        opacity: 1;
        visibility: visible;
        transform: scale(1.0);
        transition: visibility 0s linear 0s, opacity 0.25s 0s, transform 0.25s;
    }
</style>

<body>
    <a href="https://www.baidu.com/?tn=80035161_1_dg">百度一下</a>
    <button class="trigger">Click here to trigger the modal!</button>
    <div class="modal">
        <div class="modal-content">
            <span class="close-button">&times;</span>
            <h1>Hello, I am a modal!</h1>
        </div>
    </div>
    <button class="trigger">Click here to trigger the modal!</button>
    <div class="modal">
        <div class="modal-content">
            <span class="close-button">&times;</span>
            <h1>Hello, I am a modal!</h1>
        </div>
    </div>
    <script>
        var modal = document.querySelectorAll(".modal");
        var trigger = document.querySelectorAll(".trigger");
        var closeButton = document.querySelectorAll(".close-button");
        for (var i = 0; i < trigger.length; i++) {
            trigger[i].index = i;
            trigger[i].onclick = function() {
                modal[this.index].classList.add("show-modal");
            }
        }
        for (var j = 0; j < closeButton.length; j++) {
            closeButton[j].index = j;
            closeButton[j].onclick = function() {
                // console.log(this.index)

                // console.log(closeButton[this.index])
                modal[this.index].classList.remove("show-modal")
            }
        }
    </script>


</body>

</html>